package com.xxx.mall.api;

import com.xxx.mall.dto.AttachFileDTO;
import com.xxx.mall.dto.PageQuery;
import com.xxx.mall.response.R;
import com.xxx.mall.service.AttachFileService;
import com.xxx.mall.vo.AttachFileVO;
import com.xxx.mall.vo.PageVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 上传文件记录表 前端控制器
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-11-20
 */
@RestController
@RequestMapping("/attach_file")
public class AttachFileApi {

    @Resource
    AttachFileService attachFileService;

    @GetMapping("/page")
    public R<PageVO<AttachFileVO>> page(@Valid PageQuery pageQuery, String fileName, Long fileGroupId) {
        return R.ok(attachFileService.pageList(pageQuery, fileName, fileGroupId));
    }

    @PostMapping
    public R<Void> save(@RequestBody List<AttachFileDTO> list) {
        attachFileService.saveInfo(list);
        return R.ok();
    }

    @PutMapping
    public R<Void> update(@RequestBody AttachFileDTO dto) {
        attachFileService.updateNameOrGroupById(dto);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R<Void> del(@PathVariable Long id) {
        attachFileService.deleteById(id);
        return R.ok();
    }

    @DeleteMapping
    public R<Void> del(@RequestBody List<Long> ids) {
        attachFileService.deleteBatchByIds(ids);
        return R.ok();
    }

}
